<template>
<div>
  <h1>这是学部管理界面</h1>
  <el-card>
    <div class="container">
      <el-form :inline="true" :model="conditionModel">
        <el-form-item label="学部编号">
          <el-input v-model="conditionModel.departmentNo" placeholder="请输入内容" style="width: 150px" ></el-input>
        </el-form-item>
        <el-form-item label="学部名称">
          <el-input v-model="conditionModel.departmentName" placeholder="请输入内容" style="width: 150px" ></el-input>
        </el-form-item>
        <el-form-item label="校长">
          <el-select v-model="conditionModel.departmentPresident" clearable placeholder="请选择" @visible-change="searchDepartPresident">
            <el-option
                v-for="item in supplierDepartPresident"
                :key="item.techId"
                :label="item.techName"
                :value="item.techId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item  label="状态">
          <el-select v-model="conditionModel.status" placeholder="请选择" style="width: 150px">
            <el-option
                v-for="status in statusOptions"
                :key="status.value"
                :label="status.label"
                :value="status.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item >
          <el-button type="primary" @click="searchCondition">搜索</el-button>
        </el-form-item>
        <el-form-item >
          <el-button type="primary" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>

    </div>
    <el-table
        :data="tableData"
        style="width: 100%"
        border>
      <el-table-column
          prop="departId"
          label="id"
          width="150"
          align="center">
      </el-table-column>
      <el-table-column
          prop="departNo"
          label="学部编号"
          align="center">
      </el-table-column>
      <el-table-column
          prop="departName"
          label="学部名称"
          align="center">
      </el-table-column>
      <el-table-column
          prop="departPresidentName"
          label="校长"
          align="center">
      </el-table-column>
      <el-table-column
          prop="departDescription"
          label="描述"
          align="center">
      </el-table-column>
      <el-table-column
          prop="status"
          label="状态"
          align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 1" type="success" size="medium">正常</el-tag>
          <el-tag v-if="scope.row.status === 2" type="warning" size="medium">暂停</el-tag>
          <el-tag v-if="scope.row.status === 3" type="danger" size="medium">撤销</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageIndex"
        :page-sizes="[5, 10, 20, 30]"
        :page-size.sync="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total.sync="total">
    </el-pagination>
  </el-card>
</div>

</template>


<script>
  import {departInfo,positionInfo } from "@/api/discipline/depart/info"
export default {
  name: "DepartMentInfo",
  data:()=>({
    tableData:[],
    pageIndex:1,
    pageSize:10,
    total:10,
    //校长名称
    supplierDepartPresident:{},
    //专业状态
    statusOptions:[{
      label: '所有',
      value: ''
    },{
      label: '正常',
      value: '1'
    },{
      label: '暂停',
      value: '2'
    },{
      label: '撤销',
      value: '3'
    }],
    //查询条件
    conditionModel:{
      departmentNo:'',
      departmentName:'',
      departmentPresident:'',
      status:''
    }
  }),
  methods:{
    //分页显示学部信息内容
    showAllDepart(){
      let params = {
        departmentNo: this.conditionModel.departmentNo,
        departmentName: this.conditionModel.departmentName,
        departmentPresident: this.conditionModel.departmentPresident,
        status: this.conditionModel.status,
        //当前需要显示的页码
        pageIndex: this.pageIndex,
        //每页显示的条数
        pageSize: this.pageSize,
      };
      departInfo(params).then(response =>{
        this.tableData = response.data.list ;
        this.pageSize = response.data.pageSize;
        this.pageIndex = response.data.pageNum;
        this.total = response.data.total;
      })

    },
    //所在尺寸改变时
    handleSizeChange(){
      this.showAllDepart()
    },
    //所在页码改变时
    handleCurrentChange(){
      this.showAllDepart()
    },
    //查询条件 - 校长名称根据后端查询显示在前端页面select框中
    searchDepartPresident(){
      positionInfo().then(response =>{
        this.supplierDepartPresident = response.data.list;
      }).catch(err =>{
        console.log(err);
      })
    },
    //条件查询
    searchCondition(){
      this.pageIndex = 1
      this.showAllDepart()
    },
    reset(){
      this.conditionModel={}
      this.supplierDepartPresident= {}
      this.showAllDepart()
    }
  },
  created() {
    this.showAllDepart()
  }
}
</script>

<style scoped>

</style>
